package com.zhanjixun.weixin.mapper;

import com.alibaba.fastjson.JSONObject;
import com.zhanjixun.ihttp.Response;
import com.zhanjixun.ihttp.annotations.*;

import java.io.File;

/**
 * @author :zhanjixun
 * @date : 2018/11/27 13:26
 */
@UserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36")
public interface WxMapper {

    @GET
    @URL("https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_=#{_}")
    @TimestampPlaceholder(name = "_")
    Response getUUID();

    @GET
    @URL("https://login.weixin.qq.com/qrcode/#{uuid}")
    Response getQRCodeImage(@Placeholder("uuid") String uuid);

    @GET
    @URL("https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&tip=0&uuid=#{uuid}&_=#{_}&r=#{r}")
    @TimestampPlaceholder(name = "_")
    @RandomPlaceholder(name = "r", length = 10)
    Response getScanStatus(@Placeholder("uuid") String uuid);

    @GET(followRedirects = false)
    Response getWxTicket(@URL String redirectUri);

    @POST
    @URL("https://wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/webwxinit?lang=zh_CN&pass_ticket=#{pass_ticket}&r=#{r}")
    @RandomPlaceholder(name = "r", length = 10)
    Response webWxInit(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "pass_ticket", encode = true) String passTicket, @StringBodyObject JSONObject baseRequest);

    @POST
    @URL("https://wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify?lang=zh_CN&pass_ticket=#{pass_ticket}")
    Response statusNotify(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "pass_ticket", encode = true) String passTicket);

    @GET
    @URL("https://wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?lang=zh_CN&pass_ticket=#{pass_ticket}&seq=0&skey=#{skey}&r=#{r}")
    @TimestampPlaceholder(name = "r")
    Response getContact(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "pass_ticket", encode = true) String passTicket, @Placeholder("skey") String skey);

    @GET
    @URL("https://webpush.wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/synccheck?skey=#{skey}&sid=#{sid}&uin=#{uin}&synckey=#{synckey}&r=#{r}&_=#{_}")
    @TimestampPlaceholder(name = "r")
    @TimestampPlaceholder(name = "_")
    Response syncCheck(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "skey", encode = true) String skey, @Placeholder("sid") String sid, @Placeholder("uin") String uin, @Placeholder(value = "synckey", encode = true) String synckey);

    @POST
    @URL("https://wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=#{sid}&skey=#{skey}&pass_ticket=#{pass_ticket}")
    Response webWxSync(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "skey", encode = true) String skey, @Placeholder("sid") String sid, @Placeholder(value = "pass_ticket", encode = true) String passTicket, @StringBodyObject JSONObject jsonObject);

    @POST
    @URL("https://wx#{urlVersion}.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg?pass_ticket=#{pass_ticket}")
    Response webWxSendMsg(@Placeholder("urlVersion") String urlVersion, @Placeholder(value = "pass_ticket", encode = true) String passTicket, @StringBodyObject JSONObject jsonObject);

    /**
     * 撤回消息
     *
     * @param msgID
     * @param toUserName
     */
    Response webWxRevokeMsg(String msgID, String toUserName);

    /**
     * 上传媒体文件到服务器
     *
     * @param toUserName 接收用户
     * @param data       媒体文件数据
     * @param fileName   文件名称
     * @return
     */
    Response webWxUploadMedia(String toUserName, byte[] data, String fileName);

    /**
     * 上传媒体文件到服务器
     *
     * @param toUserName 接收用户
     * @param mediaData  媒体文件
     * @return mediaId 媒体文件ID
     */
    Response webWxUploadMedia(String toUserName, File mediaData);

    /**
     * 发送文件给好友
     *
     * @param toUserName 接收用户
     * @param fileName   文件名称
     * @param fileExt    文件长度
     * @param fileLen    文件后缀名
     * @param mediaId    上传文件后返回的MediaID
     * @return
     */
    Response webWxSendAppMsg(String toUserName, String fileName, long fileLen, String fileExt, String mediaId);

    /**
     * 发送图片消息
     *
     * @param toUserName 接收用户
     * @param mediaId    上传文件后返回的MediaID
     * @return
     */
    Response webWxSendMsgImg(String toUserName, String mediaId);

    /**
     * 发送视频给好友
     *
     * @param toUserName 接收用户
     * @param mediaId    上传文件后返回的MediaID
     * @return
     */
    Response webWxSendVideoMsg(String toUserName, String mediaId);

    /**
     * 发送动画表情给好友(gif图片)
     *
     * @param mediaId
     * @return
     */
    Response webWxSendEmoticon(String toUserName, String mediaId);

    /**
     * 下载消息中的图片文件
     *
     * @param msgId
     */
    Response webWxGetMsgImg(String msgId);

    /**
     * 下载消息中的语音文件
     *
     * @param msgId
     */
    Response webWxGetVoice(String msgId);

    /**
     * 下载消息中的文件
     *
     * @param fromUserName
     * @param mediaId
     */
    Response webWxGetMedia(String fromUserName, String mediaId);

    /**
     * 按照http地址名推测是获取一些分享链接的图片
     * 目前在分享位置上看到使用pictype为location
     *
     * @param msgId
     */
    Response webWxGetPublicLinkImg(String msgId);

    /**
     * 下载微信头像
     *
     * @return
     */
    Response webWxGetIcon();
}
